package cn.rulian.base.auth.bo;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import cn.rulian.base.common.bo.BaseBo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;


/** 
 * Description: 角色
 */

@Entity
@Table(name = "base_auth_role")
public class Role extends BaseBo{
	
	@Column(length = 50)
	private String name; //名称
	
	private Integer orderNum; //排序号
	
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") 
	private Date addTime = new Date(); //增加时间

	@JsonIgnore
	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinTable(name="base_auth_role_resource",
			joinColumns=@JoinColumn(name="roleId", referencedColumnName="id"), 
			inverseJoinColumns=@JoinColumn(name="resourceId", referencedColumnName="id"))
	private List<Resource> resourceList;

	@JsonIgnore
	//@ManyToMany(mappedBy="roleList")//关系交给Role端维护
	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinTable(name="base_auth_role_user",
			joinColumns=@JoinColumn(name="roleId", referencedColumnName="id"), 
			inverseJoinColumns=@JoinColumn(name="userId", referencedColumnName="id"))
	private List<User> userList;
	
	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public Integer getOrderNum()
	{
		return orderNum;
	}

	public void setOrderNum(Integer orderNum)
	{
		this.orderNum = orderNum;
	}

	public Date getAddTime()
	{
		return addTime;
	}

	public void setAddTime(Date addTime)
	{
		this.addTime = addTime;
	}

	public List<Resource> getResourceList()
	{
		return resourceList;
	}

	public void setResourceList(List<Resource> resourceList)
	{
		this.resourceList = resourceList;
	}

	public List<User> getUserList()
	{
		return userList;
	}

	public void setUserList(List<User> userList)
	{
		this.userList = userList;
	}
	
}